package com.yingxin.yxerp.module.appversion.controller;

import com.yingxin.yx.framework.commons.constant.CommonConst;
import com.yingxin.yxerp.module.appversion.entity.AppPush;
import com.yingxin.yxerp.module.appversion.service.IAppPushService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/app/push")
public class AppPushController {

    @Autowired
    private IAppPushService appPushService;

    /**
     * 创建推送信息
     * @param appPush
     */
    @PostMapping("/create")
    public void create(@RequestBody AppPush appPush){
        appPushService.createVo(appPush);
    }

    /**
     * 修改
     * @param userId
     */
    @GetMapping("/is-push/{userId}")
    public void isPush(@PathVariable("userId") String userId){
        AppPush push = appPushService.getUserIdVo(userId);
        if (push != null ){
            if (CommonConst.FALSE.equals(push.getIsPush())){
                push.setIsPush(CommonConst.TRUE);
                appPushService.updateById(push);
            }else {
                push.setIsPush(CommonConst.FALSE);
                appPushService.updateById(push);
            }
        }
    }

    /**
     * 获取用户信息
     * @param userId
     * @return
     */
    @GetMapping("/getInfo/{userId}")
    public AppPush getSetting(@PathVariable("userId") String userId){
        return appPushService.getUserIdVo(userId);
    }

    /**
     * 删除
     * @param userId
     */
    @GetMapping("/remove/{userId}")
    public void remove(@PathVariable("userId") String userId){
        appPushService.remove(userId);
    }

}
